home *** CD-ROM | disk | FTP | other *** search
/ Champak 29 / Volume 29 - JOGO DISK .iso / Games / jungle_adventure.swf / scripts / __Packages / SSBackground.as < prev    next >
Text File  |  2006-11-29  |  3KB  |  102 lines

  1. class SSBackground extends SSObject
  2. {
  3.    var autoAddToScene = false;
  4.    var assetID = null;
  5.    var className = "BG";
  6.    var left = 0;
  7.    var right = 0;
  8.    var top = 0;
  9.    var bottom = 0;
  10.    var scrollMultiplier = 1;
  11.    var tileWidth = 300;
  12.    var tileHeight = 300;
  13.    var stationary = false;
  14.    var offsetX = 0;
  15.    var offsetY = 0;
  16.    function SSBackground(tileID, depth, tileWidth, tileHeight, scrollMultiplier)
  17.    {
  18.       super();
  19.       if(tileID != null)
  20.       {
  21.          this.tileID = tileID;
  22.       }
  23.       this.z = !depth ? 20 : depth;
  24.       if(tileWidth)
  25.       {
  26.          this.tileWidth = tileWidth;
  27.       }
  28.       if(tileHeight)
  29.       {
  30.          this.tileHeight = tileHeight;
  31.       }
  32.       this.scrollMultiplier = !scrollMultiplier ? 1 : scrollMultiplier;
  33.    }
  34.    function queueForDisplay()
  35.    {
  36.    }
  37.    function setPattern(g)
  38.    {
  39.       this.pattern = g;
  40.    }
  41.    function onAddDisplay()
  42.    {
  43.       if(this.stationary)
  44.       {
  45.          this.target.attachMovie(this.tileID,"bg0",0);
  46.       }
  47.    }
  48.    function setDisplay(viewport)
  49.    {
  50.       if(this.oz != (this.oz = Math.floor(this.z - viewport.z)))
  51.       {
  52.          this.target.swapDepths(this.depth = this.calculateDepth());
  53.       }
  54.       if(this.stationary)
  55.       {
  56.          this.target._x = - this.world.target._x;
  57.          this.target._y = - this.world.target._y;
  58.          return undefined;
  59.       }
  60.       var _loc11_ = Math.floor(- this.world.target._x - (x = viewport.wTan * (viewport.x * this.scrollMultiplier) / (this.z - viewport.z) + this.offsetX));
  61.       var _loc9_ = Math.floor(- this.world.target._y - (y = viewport.wTan * (viewport.y * this.scrollMultiplier) / (this.z - viewport.z) + this.offsetY));
  62.       this.target._x = _loc11_;
  63.       this.target._y = _loc9_;
  64.       this.left = x;
  65.       this.right = x + viewport.screenWidth;
  66.       this.top = y;
  67.       this.bottom = y + viewport.screenHeight;
  68.       var _loc7_ = this.leftGrid != (this.leftGrid = Math.floor(this.left / this.tileWidth));
  69.       var _loc10_ = this.rightGrid != (this.rightGrid = Math.ceil(this.right / this.tileWidth));
  70.       var _loc8_ = this.topGrid != (this.topGrid = Math.floor(this.top / this.tileHeight));
  71.       var _loc12_ = this.bottomGrid != (this.bottomGrid = Math.ceil(this.bottom / this.tileHeight));
  72.       if(!_loc7_ && !_loc10_ && !_loc8_ && !_loc12_)
  73.       {
  74.          return undefined;
  75.       }
  76.       var _loc2_ = this.tiles.length;
  77.       while((_loc2_ = _loc2_ - 1) > -1)
  78.       {
  79.          this.tiles[_loc2_].removeMovieClip();
  80.       }
  81.       this.tiles = [];
  82.       var _loc4_ = this.rightGrid - this.leftGrid;
  83.       _loc2_ = _loc4_ * (this.bottomGrid - this.topGrid);
  84.       var _loc3_ = undefined;
  85.       var x;
  86.       var y;
  87.       var _loc5_ = 1;
  88.       while((_loc2_ = _loc2_ - 1) > -1)
  89.       {
  90.          x = this.leftGrid + _loc2_ % _loc4_;
  91.          y = y = this.topGrid + Math.floor(_loc2_ / _loc4_);
  92.          if(!(this.pattern && !(_loc5_ = this.pattern.getCell(x,y))))
  93.          {
  94.             this.tiles.push(_loc3_ = this.target.attachMovie(this.tileID,"t" + _loc2_,_loc2_));
  95.             _loc3_._x = x * this.tileWidth;
  96.             _loc3_._y = y * this.tileHeight;
  97.             _loc3_.gotoAndStop(_loc5_);
  98.          }
  99.       }
  100.    }
  101. }
  102.